﻿namespace EventBusNet6;

public static class ProjectOptionsSetting
{
    /// <summary>
    /// 注册项目配置选项
    /// </summary>
    /// <param name="services"></param>
    /// <returns></returns>
    public static IServiceCollection AddProjectOptions(this IServiceCollection services,WebApplicationBuilder builder)
    {
        FlurlHttp.Configure(settings =>
        {
            var jsonSettings = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver(), // 首字母小写（驼峰样式）
                                                                                 //NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                // ObjectCreationHandling = ObjectCreationHandling.Replace
            };
            settings.JsonSerializer = new NewtonsoftJsonSerializer(jsonSettings);
        });
      
        services.Configure<FFmpegOptions>(builder.Configuration.GetSection("FFmpeg"));
        services.Configure<LibreOfficeOptions>(builder.Configuration.GetSection("LibreOffice"));
        services.Configure<RabbitMQOptions>(builder.Configuration.GetSection("RabbitMQ"));
        services.Configure<GhostscirptOptions>(builder.Configuration.GetSection("Ghostscirpt"));

        services.AddScoped<IVideoCommandService, VideoCommandService>();
        services.AddScoped<ILibreOfficeService, LibreOfficeService>();
        services.AddScoped<IGhostscirptService, GhostscirptService>();

        services.AddHostedService<CommandHostService>();
        return services;
    }
}
